package tongwentongshu.com.app.fragment;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.BindView;
import butterknife.ButterKnife;
import tongwentongshu.com.app.R;
import tongwentongshu.com.app.db.Cache;

/**
 * Created by XiongBin on 2017/7/12.
 */

public class BasePagerFragment extends Fragment {
    public Activity mActivity;
    public View mReadView;// 我的读书列表view
    public String readingStatus;
    public String userId;
    protected Context mContext;
    RecyclerView mRecyclerView;
    SwipeRefreshLayout mSwipeRefreshLayout;

    public BasePagerFragment(Activity activity) {
        mActivity = activity;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        Bundle args = getArguments();
        mContext = getActivity();
        readingStatus = args != null ? args.getString(Cache.READING_KEY) : "";
        userId = args != null ? args.getString(Cache.USER_ID) : "";
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mReadView = initView();
        mRecyclerView = (RecyclerView) mReadView.findViewById(R.id.rv_list);
        mSwipeRefreshLayout = (SwipeRefreshLayout) mReadView.findViewById(R.id.swipeLayout);
        initData();
        return mReadView;
    }

    // 初始化布局,必须子类实现
    public View initView() {
        View view = View.inflate(mActivity, R.layout.fragment_my_reading, null);
//        ButterKnife.bind(this, view);
        return view;
    }

    // 初始化数据
    public void initData() {
    }

    public String getStatus() {
        switch (readingStatus) {
            case "1":
                return "1";
            case "2":
                return "2";
            case "3":
                return "5";
            case "4":
                return "6";
            case "5":
                return "3";
            default:
                break;
        }
        return "";
    }

    /**
     * 携带数据页面跳转
     *
     * @param clz
     * @param bundle
     */
    public void startActivity(Class<?> clz, Bundle bundle) {
        Intent intent = new Intent();
        intent.setClass(getActivity(), clz);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }
}
